import os

from pykeyboard import PyKeyboard
from pymouse import PyMouse


class FileHandler:

    @classmethod
    def read_txt(cls, path):

        with open(path, encoding='utf8') as file:
            contents = file.readlines()

        li = []
        for content in contents:
            if not content.startswith('#'):  # 以#开始的行是注释，不需要
                if not content == '\n':  # 去掉换行
                    if '#' in content:  # 判断行内是否有#号
                        temp = content.split('# ')[0].strip()  # 以#分割，去掉末尾的空格
                        li.append(temp)
                    else:
                        li.append(content.strip())
        return li

    # 基础工具类由于经常使用该类中的方法，这些方法可以使用@classmethod装饰器来简化它的使用
    @classmethod
    def read_json(cls, path):

        import json5
        with open(path, encoding='utf8') as file:

            contents = json5.load(file)  # 读取json文件
        return contents

    @classmethod
    def read_dir(cls, path):
        import os
        all = os.listdir(path)
        li = []
        for a in all:
            if a.endswith('.csv'):
                a = f'{path}\\{a}'
                li.append(a)
        return li



if __name__ == '__main__':
    pass
